package org.base.sys.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.base.common.annotation.Log;
import org.base.sys.enums.BizType;
import org.base.sys.VO.SysRoleVO;
import org.base.sys.enums.RoleStatus;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.base.common.controller.BaseController;
import org.base.sys.pojo.SysRole;
import org.base.sys.service.SysRoleService;
import org.base.sys.query.SysRoleQuery;
import java.util.List;
import javax.validation.Valid;

import org.base.common.pojo.PageResult;

/**
 * <p>
 * 角色信息 前端控制器
 * </p>
 *
 * @author AutoGenerator
 * @since 2020-05-27
 */
@Api(value = "角色信息", tags = "角色信息")
@Validated
@AllArgsConstructor
@RestController
@RequestMapping("/sys-role")
@Slf4j
public class SysRoleController extends BaseController<SysRole, SysRoleService> {

    /**
    * 添加
    */
    @PostMapping("/add")
    @ApiOperation(value = "添加角色信息")
    public boolean add(@Valid @RequestBody SysRole entity){
        return service.save(entity);
    }

    /**
    * 根据id查询
    */
    @GetMapping("/{id}")
    @ApiOperation(value = "根据id查询角色信息")
    public SysRoleVO get(@PathVariable("id") Long id){
        return service.getRoleVOById(id);
    }

    /**
    * 更新
    */
    @PutMapping("/update")
    @ApiOperation(value = "根据id更新角色信息")
    public boolean update(@Valid @RequestBody SysRole entity){
        return service.updateById(entity);
    }

    /**
    * 查询
    */
    @GetMapping("/query")
    @ApiOperation(value = "列表查询角色信息")
    public List<SysRole> query(SysRoleQuery query){
        return service.getByQuery(query);
    }

    /**
    * 分页查询
    */
    @GetMapping("/pageQuery")
    @ApiOperation(value = "分页查询角色信息")
    public PageResult pageQuery(SysRoleQuery query){
        return service.getByPageQuery(query);
    }


    /**
     * 添加或者保存
     */
    @PostMapping("/saveOrUpdate")
    @Log(bizType = BizType.INSERT_UPDATE)
    public boolean saveOrUpdate(@Valid @RequestBody SysRoleVO entity){
        return service.saveOrUpdateRoleVO(entity);
    }


    @PutMapping("/enable/{id}")
    public boolean enable(@PathVariable("id") Long id){
        return service.enable(id);
    }

    @PutMapping("/disable/{id}")
    public boolean disable(@PathVariable("id") Long id){
        return service.disable(id);
    }


    @GetMapping("/roleStatus")
    public RoleStatus[] getRoleStatus() {
        return RoleStatus.values();
    }

}

